﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;

namespace WhereIsMyCash
{
    /// <summary>
    /// 扩展类
    /// </summary>
    public static class Extend
    {
        /// <summary>
        /// 原始字符串转换为MD5加密字符串
        /// </summary>
        /// <param name="str">原始字符串</param>
        /// <returns></returns>
        public static string ToMD5Hash(this string str)
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");
        }

        /// <summary>
        /// 将一个路径字符串映射为服务器磁盘路径
        /// </summary>
        /// <param name="str">路径字符串</param>
        /// <returns></returns>
        public static string ToFilePath(this string str)
        {
            return HttpContext.Current.Server.MapPath(str);
        }

        /// <summary>
        /// 将一个路径字符串映射为客户端浏览器可用的http路径
        /// </summary>
        /// <param name="str">路径字符串</param>
        /// <returns></returns>
        public static string ToRelativePath(this string str)
        {
            return new Control().ResolveClientUrl(str);
        }
    }
}
